/**
 * 
 */
package cn.panda.edu.teacher;

import cn.panda.edu.model.Section;
import cn.panda.edu.service.SectionService;
import cn.panda.edu.util.ResultDataUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 类描述：
 * 
 */
@RestController
@RequestMapping("/api/teacher/section")
public class TeacherSectionController {

	@Autowired
	private SectionService sectionService;

	@ApiOperation(value = "显示章节列表和小节")
	@ApiImplicitParam(name = "courseId", value = "课程id", required = true, dataType = "Integer")
	@RequestMapping(value = "list", method = RequestMethod.POST)
	public Object getAllSection(String sectionName, Integer courseId) {
		List<Section> list = sectionService.getAllSection(sectionName,courseId);
		return ResultDataUtil.resData(200, "", list);
	}
	@ApiOperation(value = "添加章节")
	@ApiImplicitParam(name = "section", value = "章节类", required = false, dataType = "Section ")
	@RequestMapping(value = "insert", method = RequestMethod.POST)
	public  Object insert(Section section) {
		int status=200;
		String message=null;
		try {
			section.setSectionModifyDate(new Date());
			sectionService.insertSelective(section);
			status=200;
			message="添加成功!";
		} catch (Exception e) {
			status=500;
			message="添加失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
	@ApiOperation(value = "修改章节")
	@RequestMapping(value = "update", method = RequestMethod.POST)
	public  Object update(@RequestBody Section section) {
		int status=200;
		String message=null;
		try {
			section.setSectionModifyDate(new Date());
			sectionService.updateByPrimaryKeySelective(section);
			status=200;
			message="修改成功!";
		} catch (Exception e) {
			status=500;
			message="修改失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}

}
